local f = CreateFrame("Frame", "jMinimap", Minimap)

local function init(self)
	TimeManager_LoadUI()

	MinimapCluster:SetMovable(true)
	MinimapCluster:SetUserPlaced(true)

	local frames = {
		MinimapZoomIn,
		MinimapZoomOut,
		MinimapToggleButton,
		MinimapBorderTop,
		MiniMapWorldMapButton,
	}

	Minimap:SetScript("OnMouseDown", function(self)
		if(IsAltKeyDown()) then
			MinimapCluster:ClearAllPoints()
			MinimapCluster:StartMoving()
		else
			Minimap_OnClick(self)
		end
	end)
	Minimap:SetScript("OnMouseUp", function()
		MinimapCluster:StopMovingOrSizing()
	end)

	Minimap:EnableMouseWheel(true)
	Minimap:SetScript("OnMouseWheel", function(self, z)
		local c = Minimap:GetZoom()
		if(z > 0 and c < 5) then
			Minimap:SetZoom(c + 1)
		elseif(z < 0 and c > 0) then
			Minimap:SetZoom(c - 1)
		end
	end)

	MiniMapBattlefieldFrame:SetParent(Minimap)
	MiniMapBattlefieldFrame:ClearAllPoints()
	MiniMapBattlefieldFrame:SetPoint("TOPLEFT", 0, -3)

	MiniMapMailBorder:Hide()
	MiniMapMailFrame:SetParent(Minimap)
	MiniMapMailFrame:ClearAllPoints()
	MiniMapMailFrame:SetPoint"TOP"
	MiniMapMailIcon:SetTexture"Interface\\AddOns\\jerry\\mail"

	self:ClearAllPoints()
	self:SetPoint("TOPLEFT", Minimap, -5, 4)

	self:SetSize(149, 149)

	self:SetFrameLevel(0)
	self:SetFrameStrata"BACKGROUND"

	self:SetBackdropColor(0, 0, 0, .4)

--~ 	local zone = MinimapZoneText
--~ 	zone:SetFont(STANDARD_TEXT_FONT, 12,"OUTLINE")
--~ 	zone:SetDrawLayer"OVERLAY"
--~ 	zone:ClearAllPoints()
--~ 	zone:SetPoint("LEFT", self, 5, 0)
--~ 	zone:SetPoint("RIGHT", self, -5, 0)
--~ 	zone:SetPoint("TOP", self, 0, 15)

	for _, frame in ipairs(frames) do
		frame:Hide()
	end
	Minimap_UpdateRotationSetting()

	if TimeManagerFrame then
		TimeManagerFrame:ClearAllPoints()
		TimeManagerFrame:SetPoint("TOPRIGHT", MinimapCluster, "BOTTOMRIGHT", 45, 0)
	end
end

if not IsLoggedIn() then
	f:SetScript("OnEvent", function (self)
		init(self)
		self:UnregisterEvent"PLAYER_LOGIN"
		self:SetScript("OnEvent", nil)
	end)
	f:RegisterEvent"PLAYER_LOGIN"
else
	init(f)
end
